<?php
namespace WebApper\Shortcode;

/*
 * [service]
 *
 */
 class reportingRep extends \WebApper\Shortcode {
	
    /**
     * Define shortcode properties
     *
     */
	protected $shortcode = 'reportingRep';

    /**
     * Initialize the Shortcode Class
     *
     */
    public function __construct() {
		add_shortcode( $this->shortcode, array($this, 'shortcode') );
		add_action( 'wp_ajax_web_apper' . $this->shortcode, array($this, 'sendAjaxResponse') );
		add_action( 'wp_ajax_nopriv_web_apper' . $this->shortcode, array($this, 'sendAjaxResponse') );	   	
	}

    /**
     * Handles the add post shortcode
     *
     * @param array $atts
     */
	 
    public function shortcode( $atts ) {

		global $wpdb, $webapper;
		?>
<div class="span10">
<h3>Reporting Rep</h3>
  <table>
    <tr>
      <td><b>Payments Received</b></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;39</td>
    </tr>
    <tr>
      <td><b>Payments Remaining</b></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;403</td>
    </tr>
    <tr>
      <td><b>Amount Paid</b></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;$127000</td>
    </tr>
    <tr>
      <td><b>Balance</b></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;$540,00</td>
    </tr>
    <tr>
      <td><b>Default Amount</b></td>
      <td>&nbsp;&nbsp;&nbsp;&nbsp;$2,700</td>
    </tr>
  </table>
  </br>
  <table id="reportingRep" class="table table-bordered table-striped" >
    <thead>
      <tr>
        <td></td>
        <td colspan="2">New </td>
        <td colspan="4">Past</td>
      </tr>
      <tr>
        <td>Rep/Company</td>
        <td>Gross Sold</td>
        <td>Gross Collected</td>
        <td>Gross Bulled</td>
        <td>Gross Collected</td>
        <td>Defaulted</td>
        <td>'#' enrolled</td>
      </tr>
    </thead>
    <tbody>
    <?php 
		$user_id       = get_current_user_id();
		$reporting_rep = $webapper->tables->reporting_rep;
		$reporting_rep_rows = $wpdb->get_results("SELECT * FROM {$reporting_rep}  WHERE user_id='$user_id' ORDER BY reporting_rep_id ASC");
		foreach ($reporting_rep_rows as $row)
		{
      		echo '<tr>';
				/*echo '<td>'.$row ->client_name.'</td>';*/
				echo '<td>Name frome lead index(Joe)</td>';
				echo '<td>'.$row->newBiz_gross_sold.'</td>';
				echo '<td>'.$row->newBiz_gross_collected.'</td>';
       			echo '<td>'.$row->pastBiz_gross_billed.'</td>';
				echo '<td>'.$row->pastBiz_gross_collected.'</td>';
				echo '<td>'.$row->pastBiz_defaulted_amount.'</td>';
				echo '<td>'.$row->pastBiz_enrolled.'</td>';
      		echo '</tr>';
		 } 
	?>
    </tbody>
  </table>

<script type="text/javascript">
    	nTable = jQuery('#reportingRep');
		jQuery(document).ready(function($){
			// Initialize dataTable					
					oTable = $(nTable).dataTable({
						<?php
							// Build the sDom parameter for dataTables
							global $template;
							if ( stristr($template, 'fullwidth') ) :
								$spanA = 7; $spanB = 7;
							else :
								$spanA = 4; $spanB = 5;
							endif;
							echo "'sDom': \" <'row' <'span1' C> <'#operationLabel'> <'span".$spanB."' <'#temp'> f>r>t<'row'<'span3'i><'span3'l><'span4'p>>\",\n";
						?>
						'sPaginationType': 'bootstrap',
						'aaSorting': [[ 0, 'desc']],
						'oLanguage': {
							'sLengthMenu': 'records per page <select>'+
							'<option value="10">10</option>'+
							'<option value="20">20</option>'+
							'<option value="30">30</option>'+
							'<option value="40">40</option>'+
							'<option value="50">50</option>'+
							'<option value="100">100</option>'+
							'</select>'
						},
						//'aoColumnDefs': [ { 'bVisible': false, 'aTargets': [  0 ] } ],
						'oColVis': {
							'buttonText': 'Columns',
						    'bRestore': true,
							'sAlign': 'left',
							'sSize': 'css',
							
						},
					
					});
					$("#operationLabel").addClass("span2 btn-group");
					$("#operationLabel").html("<button class='btn  btn-primary' id='currentmonth_<?php echo $id; ?>_datatable' >Curr Month</button><button class='btn  btn-primary' id='previousmonth_<?php echo $id; ?>_datatable' >Prev Month</button>");
					$("#temp").addClass("span3");
					$("#temp").html('<input id="reserveDateFrom" style="width:90px;" type="text" value="2014-01-13" name="selectedDay"></input>&nbsp;<input id="reserveDateFrom" style="width:90px;" type="text" value="2014-01-13" name="selectedDay"></input>');
						
								

		$.extend($.fn.datepicker.defaults, {
        parse: function (string) {
          var matches;
          if ((matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/))) {
            return new Date(matches[3], matches[1] - 1, matches[2]);
          } else {
            return null;
          }
        },
        format: function (date) {
          var
            month = (date.getMonth() + 1).toString(),
            dom = date.getDate().toString();
          if (month.length === 1) {
            month = "0" + month;
          }
          if (dom.length === 1) {
            dom = "0" + dom;
          }
         // return month + "/" + dom + "/" + date.getFullYear();
		  return dom + "/" + month + "/" + date.getFullYear();
        }
      });  
		
		});
		
    </script>
<?php	
	}		
}
$initialize = new reportingRep(); 
?>
